#!/usr/bin/python3

# 基本数据类型
count = 100 #整型变量
name = "John" #字符串变量
pi = 3.14159 #浮点型变量
is_student = True #布尔型变量

print(count)
print(name)
print(pi)
print(is_student)

print("====="*10)

# 通过type()函数查看变量的数据类型
print(type(count))
print(type(name))
print(type(pi))
print(type(is_student))

print("====="*10)

# 多个变量赋值
a, b, c = 10, "hello", True
print(a)
print(b)
print(c)

d=e=f = 10.3
print(d)
print(e)
print(f)

print("====="*10)

# 使用instace()函数判断变量是否为某种数据类型
print(isinstance(count, int))
print(isinstance(name, str))
print(isinstance(pi, int))

print("====="*10)

print(issubclass(bool, int)) # bool是否是int的子类
print(True + 10) # 布尔型变量不能直接与数字进行运算，需要先转换为数字类型
print(int(True)) # 转换为整数类型
print(False + 10) # 布尔型变量不能直接与数字进行运算，需要先转换为数字类型
print(int(False)) # 转换为整数类型

print("====="*10)

# String 类型
s1 = "Hello, world!"
s2 = 'Python is awesome'
s3 = """This is a multi-line string.
        It can be used for writing comments or documentation."""
print(s1)
print(s2)
print(s3)

# 字符串的截取
print(s1[0]) # 输出 H
print(s1[2:5]) # 输出 llo
print(s1[2:]) # 输出 llo, world!
print(s1[:5]) # 输出 Hello
print(s1[-1]) # 输出 !
print(s1[-5:-2]) # 输出 orl

print("====="*10)

# bool 类型
print(bool(0)) # False
print(bool(1)) # True
print(bool(-1)) # True
print(bool(0.0)) # False
print(bool(3.14)) # True
print(bool("")) # False
print(bool("hello")) # True
print(bool(None)) # False
print(bool([])) # False
print(bool([1, 2, 3])) # True
print(bool({})) # False
print(bool({'name': 'John', 'age': 25})) # True

print("====="*10)

# List 类型
my_list = [1, 2, "3", 4, 5]
print(my_list)
print(my_list[-1::-1]) # 数组的反转

# 列表的操作
my_list[1] = "oo"
print(my_list)
my_list.append("new")
print(my_list)
my_list.append([5, 6, 7])
print(my_list)
my_list.append((7,8))
print(my_list)
print(len(my_list))
print(my_list.pop(1))
print(my_list)

print("====="*10)

# Tuple 类型
my_tuple = (1, 2, "3", 4, 5)
print(my_tuple)
print(my_tuple[-1::-1]) # 元组的反转

print("====="*10)

# Set 类型
my_set = {1, 2, "3", 4, 5, 2}
print(my_set)
set1 = set("abcdef")
print(set1)
set2 = set()
print(set2)
set2.add(1)
set2.add(2)
set2.add(3)
print(set2)
set2.remove(2)
print(set2)



print("====="*10)

# Dictionary 类型
my_dict = {"name": "John", "age": 25, "city": "New York"}
print(my_dict)
print(my_dict["name"])
print(my_dict.keys())
print(my_dict.values())
print(my_dict.items())

print("====="*10)